srvMap.add('queryLogList', '','front/sh/logService!execute?uid=queryLogList');//查询日志列表

var startDate = "";
var endDate = "";
var logType = "";
var downPath = "";

var queryDate = {
		elem : "#queryDate",
		format : 'YYYY/MM/DD',
		max : laydate.now(),
		istime : false,
		istoday : true,
		festival: true, //显示节日
		choose : function (){
			queryLogList();
		}
};

$(document).ready(function() {
	
	showDate();
	jQuery("#queryDate").val(getToday());
	
	// 初始化分页
	page = new Page("#pageBox", queryLogList);
	
	// 初始化日志列表
	queryLogList();
	
	jQuery(".button_blue").on("click",function(){
		queryLogList();
	});
});

/**
 * 初始化日志列表
 */
function showLogList(result) {
	$("#doNone").hide();
	var pageInfo = page.getPageInfo();
	
	page.initPages(result.totalNumber, result.totalPage);
	var curPage=parseInt(result.curPage);
	var pageSize=parseInt(result.pageSize);
	var data = result.data;

	var strs = [];
	if (null == data || data.length<=0 || $.isEmptyObject(data)) {
		strs.push("<tr><td align='center' colspan='8' style='color:red;'>没有相关数据！</td></tr>");
		strs = strs.join("");
		$("#logList").empty().append($(strs));
		$("#doNone").show();
		$(".data-table-loading").hide();
		return;
	}
		
	for (var i = 0, len = data.length; i < len; i++) {
		var l = data[i];

		var logContent = l.logContent==null?"": l.logContent;
		var funcId = l.funcId==null?"": l.funcId;
		var funcName = l.funcName==null?"":l.funcName;
		var userId = l.userId==null?"": l.userId;
		var userName = l.userName==null?"": l.userName;
		var logType = l.logType==null?"": l.logType;
		var logTime = l.logTime==null?"":l.logTime;
		
		if(logTime.length == 14){
			
			logTime = logTime.substr(8,2) + ":" + logTime.substr(10,2) + ":" + logTime.substr(12,2);
			
		}
		
		logContent = logContent.replace(/</g, "&lt;");
		logContent = logContent.replace(/>/g, "&gt;");
		if ("visit" == logType) {
			logType = "访问日志";
		} else if ("operator" == logType) {
			logType = "操作日志";
		} else if ("warning" == logType) {
			logType = "警告日志";
		} else if ("webservice" == logType) {
			logType = "webservice日志";
		} else {
			logType = "未知日志";
		}
		// 表格展现
		var str = '<tr><td class="td-c">$0</td><td class="td-c">$1</td><td class="td-c">$2</td><td class="td-c">$3</td><td class="td-c">$4</td><td class="td-c">$5</td><td class="td-c">$6</td><td class="td-c">$7</td></tr>';
		str=str.replace(/\$0/g,(i+1)+pageSize*(curPage-1));
		str=str.replace(/\$1/g,logType);
		str=str.replace(/\$2/g,logContent);
		str=str.replace(/\$3/g,funcId);
		str=str.replace(/\$4/g,funcName);
		str=str.replace(/\$5/g,userId);
		str=str.replace(/\$6/g,userName);
		str=str.replace(/\$7/g,logTime);
		strs.push(str);
	}
	strs = strs.join("");
	$("#logList").empty().append($(strs));
	if(data.length<3){
		$("#doNone").show();
	}
	$(".data-table-loading").hide();
}

/**
 * 查询日志列表
 */
function queryLogList() {
	$(".data-table-loading").show();
	var pageInfo = page.getPageInfo();
	var keyword = $(".search-input").val();
	pageInfo.keyword = keyword;
	pageInfo.queryDate = $("#queryDate").val();

	
	var par = "&keyword="+keyword+"&queryDate="+$("#queryDate").val()+"&curPage="+pageInfo.curPage+"&pageSize="+pageInfo.pageSize;
	Util.ajax.postJsonSync(srvMap.get('queryLogList'),par,function(json,status){
		if(status){
			showLogList(json.object.result);
		}else{
			 alert('错误','数据异常！');   
		}
	});
	
//	var url = CONTENT_PATH
//			+ "/com.asiainfo.manage.LogAction.queryLogList.invoke?num="
//			+ new Date();
//	Base.ajax({
//		url : url,
//		data : pageInfo,
//		success : function(req) {
//			if (null == req || null == req.result) {
//				return;
//			}
//
//			showLogList(req.result);
//		}
//	});
}

function showDate(){
	laydate(queryDate);
}

$(document).keydown(function(e) {
	var keycode = e.keyCode;
	if (keycode == 13) {
		$(".button_blue").click();
	}
});
